package cn.usts.edu.lesson05;

import javax.swing.*;
import java.awt.*;

public class JPanelDemo extends JFrame {

    public JPanelDemo() {
        this.setTitle("JPanel");
        this.setBounds(100,100,400,400);
        this.setVisible(true);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        this.setLayout(new GridLayout(2,2,10,20));// 后边的两个参数都是  行间距  和  列间距
        JPanel panel01 = new JPanel(new GridLayout(1,3));
        JPanel panel02 = new JPanel(new GridLayout(3,1));
        JPanel panel03 = new JPanel(new GridLayout(2,3,10,10));
        JPanel panel04 = new JPanel(new GridLayout(2,2));

        JButton button1 = new JButton("1");
        JButton button2 = new JButton("1");
        JButton button3 = new JButton("1");

        JButton button4 = new JButton("2");
        JButton button5 = new JButton("2");
        JButton button6 = new JButton("2");

        JButton button7 = new JButton("3");
        JButton button8 = new JButton("3");
        JButton button9 = new JButton("3");
        JButton button10 = new JButton("3");
        JButton button11 = new JButton("3");
        JButton button12 = new JButton("3");

        JButton button13 = new JButton("4");
        JButton button14 = new JButton("4");
        JButton button15 = new JButton("4");
        JButton button16 = new JButton("4");

        panel01.add(button1);
        panel01.add(button2);
        panel01.add(button3);

        panel02.add(button4);
        panel02.add(button5);
        panel02.add(button6);

        panel03.add(button7);
        panel03.add(button8);
        panel03.add(button9);
        panel03.add(button10);
        panel03.add(button11);
        panel03.add(button12);

        panel04.add(button13);
        panel04.add(button14);
        panel04.add(button15);
        panel04.add(button16);


        Container container = this.getContentPane();
        container.add(panel01);
        container.add(panel02);
        container.add(panel03);
        container.add(panel04);

    }

    public static void main(String[] args) {
        new JPanelDemo();
    }
}
